new Vue({
  el: '#app',
  data() {
    return {
      form: {
        page: 1,			//页数
        limit: 10,			//每页数据条数
        Enterprise_Info_SerialNumber: $.cookie('enterprise'),
        token: $.cookie('token')
      },
      formData: {},
      tableData: [],		//表格数据
      total: 1,
      dialogForm: false,
      title: '',
      multipleSelection: []
    }
  },
  mounted() {
    this.getList(this.form);
  },
  methods: {
    onSerach() {				//查询方法
      let _this = this
      console.log(_this.form.serachKey)
    },
    addContract() {
      console.log("跳转")
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form)
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form)
    },
    getList(data) {     //换页方法
      let _this = this
      $.ajax({
        type: 'POST',
        url: DomainName + "/getTraceabilitybaseAll",
        data,
        success: function (Result) {
          if (Result.Status == "success") {
            _this.tableData = Result.tableData
            _this.total = parseInt(Result.limit)
          }
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
    },
    addhandle() {
      window.location.href = './Add.html'
    },
    editMember(Traceability_Base_SerialNumber) {
      sessionStorage.setItem("Traceability_Base_SerialNumber", Traceability_Base_SerialNumber)
      window.location.href = './Edit.html?Traceability_Base_SerialNumber=' + Traceability_Base_SerialNumber
    },
    deletMember(Traceability_Base_SerialNumber) {
      this.$confirm('此操作将删除该生产基地, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        this.delete(Traceability_Base_SerialNumber);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    delete(Traceability_Base_SerialNumber) {
      const _this = this
      $.ajax({
        url: DomainName + '/getInquiryIDOriginal',
        type: 'POST',
        data: {
          token: $.cookie('token'),
          Data: 'traceabilitybase_info',
          Primary_Key_Name: 'Traceability_Base_SerialNumber',
          Primary_Key: Traceability_Base_SerialNumber
        },
        success: function (res) {
          if (res.length == 1) {
            res[0].Row_Status = '1'
            $.ajax({
              url: DomainName + '/getEditAction',
              type: 'POST',
              data:{ Data: JSON.stringify({ Modify: { traceabilitybase_info: [res[0]] } }), token: $.cookie('token') },
              success:function (res) {
                if (res.Status == 'success') {
                  _this.getList(_this.form);
                  _this.$message({
                    type: 'success',
                    message: '删除成功!'
                  });
                }
              },
              error: function () {
                _this.$message.error("删除失败，请稍后再试")
              },
              complete: function (XMLHttpRequest) {
                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                  window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                }
              }
            })
          }
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    }
  },
})